package demo02;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
//修改随机点名器案列
public class HomeWork08 {
    public static void main(String[] args){
        System.out.println("--------随机点名器---------");
        ArrayList<Student> list = new ArrayList<Student> ();
        addStudentName(list);
        printStudentName(list);
        randomStudentName(list);
    }

    private static void addStudentName(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生姓名：");
            String name = sc.next();
            Student student = new Student(name);
            list.add(student);
        }
    }

    private static void printStudentName(ArrayList<Student> list){
        for (int i = 0; i < list.size(); i++) {
            System.out.println("第" + (i + 1) + "个学生姓名为: " + list.get(i).getName());
        }
    }

    private static void randomStudentName(ArrayList<Student> list) {
        Random r = new Random();
        int index = r.nextInt(list.size());
        System.out.println("幸运儿是：" + list.get(index).getName());
    }
}